<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Configuring Zend_Console_Getopt - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.console.getopt.configuration.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.console.getopt.configuration.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.controller.html">Zend_Controller</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.console.getopt.configuration" class="section"><div class="info"><h1 class="title">Configuring Zend_Console_Getopt</h1></div>
    

    <div class="section" id="zend.console.getopt.configuration.addrules"><div class="info"><h1 class="title">Adding Option Rules</h1></div>
        

        <p class="para">
            You can add more option rules in addition to those you specified
            in the <span class="classname">Zend_Console_Getopt</span> constructor, using the
             <span class="methodname">addRules()</span> method. The argument to
             <span class="methodname">addRules()</span> is the same as the first argument to the
            class constructor. It is either a string in the format of the
            short syntax options specification, or else an associative array
            in the format of a long syntax options specification.
            See <a href="zend.console.getopt.rules.html" class="link">Declaring Getopt Rules</a>
            for details on the syntax for specifying options.
        </p>

        <div class="example" id="zend.console.getopt.configuration.addrules.example"><div class="info"><p><b>Example #1 Using addRules()</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
$opts-&gt;addRules(
  array(
    &#039;verbose|v&#039; =&gt; &#039;Print verbose output&#039;
  )
);
</pre>

        </div>

        <p class="para">
            The example above shows adding the <strong class="command">--verbose</strong> option
            with an alias of <strong class="command">-v</strong> to a set of options
            defined in the call to the constructor. Notice that you can mix
            short format options and long format options in the same instance
            of <span class="classname">Zend_Console_Getopt</span>.
        </p>
    </div>

    <div class="section" id="zend.console.getopt.configuration.addhelp"><div class="info"><h1 class="title">Adding Help Messages</h1></div>
        

        <p class="para">
            In addition to specifying the help strings when declaring option
            rules in the long format, you can associate help strings
            with option rules using the  <span class="methodname">setHelp()</span>
            method. The argument to the  <span class="methodname">setHelp()</span> method is an
            associative array, in which the key is a flag, and the value is a
            corresponding help string.
        </p>

        <div class="example" id="zend.console.getopt.configuration.addhelp.example"><div class="info"><p><b>Example #2 Using setHelp()</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
$opts-&gt;setHelp(
    array(
        &#039;a&#039; =&gt; &#039;apple option, with no parameter&#039;,
        &#039;b&#039; =&gt; &#039;banana option, with required integer parameter&#039;,
        &#039;p&#039; =&gt; &#039;pear option, with optional string parameter&#039;
    )
);
</pre>

        </div>

        <p class="para">
            If you declared options with aliases, you can use any of the
            aliases as the key of the associative array.
        </p>

        <p class="para">
            The  <span class="methodname">setHelp()</span> method is the only way to define help
            strings if you declared the options using the short syntax.
        </p>
    </div>

    <div class="section" id="zend.console.getopt.configuration.addaliases"><div class="info"><h1 class="title">Adding Option Aliases</h1></div>
        

        <p class="para">
            You can declare aliases for options using the  <span class="methodname">setAliases()</span>
            method. The argument is an associative array, whose key is
            a flag string declared previously, and whose value is a new
            alias for that flag. These aliases are merged with any existing
            aliases. In other words, aliases you declared earlier are
            still in effect.
        </p>

        <p class="para">
            An alias may be declared only once. If you try to redefine
            an alias, a <span class="classname">Zend_Console_Getopt_Exception</span> is thrown.
        </p>

        <div class="example" id="zend.console.getopt.configuration.addaliases.example"><div class="info"><p><b>Example #3 Using setAliases()</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
$opts-&gt;setAliases(
    array(
        &#039;a&#039; =&gt; &#039;apple&#039;,
        &#039;a&#039; =&gt; &#039;apfel&#039;,
        &#039;p&#039; =&gt; &#039;pear&#039;
    )
);
</pre>

        </div>

        <p class="para">
            In the example above, after declaring these aliases,
            <strong class="command">-a</strong>, <strong class="command">--apple</strong> and
            <strong class="command">--apfel</strong> are aliases for each other.
            Also <strong class="command">-p</strong> and <strong class="command">--pear</strong> are aliases
            for each other.
        </p>

        <p class="para">
            The  <span class="methodname">setAliases()</span> method is the only way to define aliases
            if you declared the options using the short syntax.
        </p>
    </div>

    <div class="section" id="zend.console.getopt.configuration.addargs"><div class="info"><h1 class="title">Adding Argument Lists</h1></div>
        

        <p class="para">
            By default, <span class="classname">Zend_Console_Getopt</span> uses
            <var class="varname">$_SERVER[&#039;argv&#039;]</var> for the array of command-line
            arguments to parse. You can alternatively specify the array of
            arguments as the second constructor argument. Finally, you
            can append more arguments to those already used using the
             <span class="methodname">addArguments()</span> method, or you can replace the current
            array of arguments using the  <span class="methodname">setArguments()</span> method.
            In both cases, the parameter to these methods is a simple array of
            strings. The former method appends the array to the current
            arguments, and the latter method substitutes the array for the
            current arguments.
        </p>

        <div class="example" id="zend.console.getopt.configuration.addargs.example"><div class="info"><p><b>Example #4 Using addArguments() and setArguments()</b></p></div>
            

            <pre class="programlisting brush: php">
// By default, the constructor uses $_SERVER[&#039;argv&#039;]
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);

// Append an array to the existing arguments
$opts-&gt;addArguments(array(&#039;-a&#039;, &#039;-p&#039;, &#039;p_parameter&#039;, &#039;non_option_arg&#039;));

// Substitute a new array for the existing arguments
$opts-&gt;setArguments(array(&#039;-a&#039;, &#039;-p&#039;, &#039;p_parameter&#039;, &#039;non_option_arg&#039;));
</pre>

        </div>
    </div>

    <div class="section" id="zend.console.getopt.configuration.config"><div class="info"><h1 class="title">Adding Configuration</h1></div>
        

        <p class="para">
            The third parameter to the <span class="classname">Zend_Console_Getopt</span>
            constructor is an array of configuration options that affect
            the behavior of the object instance returned. You can also
            specify configuration options using the  <span class="methodname">setOptions()</span>
            method, or you can set an individual option using the
             <span class="methodname">setOption()</span> method.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Clarifying the Term &quot;option&quot;</b><br /></span>
            

            <p class="para">
                The term &quot;option&quot; is used for configuration of the
                <span class="classname">Zend_Console_Getopt</span> class to match terminology
                used elsewhere in Zend Framework. These are not the same
                things as the command-line options that are parsed by
                the <span class="classname">Zend_Console_Getopt</span> class.
            </p>
        </p></blockquote>

        <p class="para">
            The currently supported
            options have const definitions in the class. The options,
            their const identifiers (with literal values in parentheses)
            are listed below:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <b><tt>Zend_Console_Getopt::CONFIG_DASHDASH</tt></b> (&quot;dashDash&quot;),
                    if <b><tt>TRUE</tt></b>, enables the special flag <strong class="command">--</strong> to
                    signify the end of flags. Command-line arguments following
                    the double-dash signifier are not interpreted as options,
                    even if the arguments start with a dash. This configuration
                    option is <b><tt>TRUE</tt></b> by default.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <b><tt>Zend_Console_Getopt::CONFIG_IGNORECASE</tt></b> (&quot;ignoreCase&quot;),
                    if <b><tt>TRUE</tt></b>, makes flags aliases of each other if they differ
                    only in their case. That is, <strong class="command">-a</strong> and
                    <strong class="command">-A</strong> will be considered to be synonymous flags.
                    This configuration option is <b><tt>FALSE</tt></b> by default.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <b><tt>Zend_Console_Getopt::CONFIG_RULEMODE</tt></b>
                    (&quot;ruleMode&quot;) may have values
                    <b><tt>Zend_Console_Getopt::MODE_ZEND</tt></b> (&quot;zend&quot;) and
                    <b><tt>Zend_Console_Getopt::MODE_GNU</tt></b> (&quot;gnu&quot;). It should not be
                    necessary to use this option unless you extend the class with additional syntax
                    forms. The two modes supported in the base
                    <span class="classname">Zend_Console_Getopt</span> class are unambiguous. If the
                    specifier is a string, the class assumes <b><tt>MODE_GNU</tt></b>,
                    otherwise it assumes <b><tt>MODE_ZEND</tt></b>. But if you extend the
                    class and add more syntax forms, you may need to specify the mode
                    using this option.
                </p>
            </li>
        </ul>

        <p class="para">
            More configuration options may be added as future enhancements
            of this class.
        </p>

        <p class="para">
            The two arguments to the  <span class="methodname">setOption()</span> method are
            a configuration option name and an option value.
        </p>

        <div class="example" id="zend.console.getopt.configuration.config.example.setoption"><div class="info"><p><b>Example #5 Using setOption()</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
$opts-&gt;setOption(&#039;ignoreCase&#039;, true);
</pre>

        </div>

        <p class="para">
            The argument to the  <span class="methodname">setOptions()</span> method is
            an associative array. The keys of this array are the configuration
            option names, and the values are configuration values.
            This is also the array format used in the class constructor.
            The configuration values you specify are merged with the current
            configuration; you don&#039;t have to list all options.
        </p>

        <div class="example" id="zend.console.getopt.configuration.config.example.setoptions"><div class="info"><p><b>Example #6 Using setOptions()</b></p></div>
            

            <pre class="programlisting brush: php">
$opts = new Zend_Console_Getopt(&#039;abp:&#039;);
$opts-&gt;setOptions(
    array(
        &#039;ignoreCase&#039; =&gt; true,
        &#039;dashDash&#039;   =&gt; false
    )
);
</pre>

        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.controller.html">Zend_Controller</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.console.getopt.html">Zend_Console_Getopt</a></li>
  <li><a href="zend.console.getopt.introduction.html">Introduction</a></li>
  <li><a href="zend.console.getopt.rules.html">Declaring Getopt Rules</a></li>
  <li><a href="zend.console.getopt.fetching.html">Fetching Options and Arguments</a></li>
  <li class="active"><a href="zend.console.getopt.configuration.html">Configuring Zend_Console_Getopt</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>